package com.shuangk.majingze.coolpapa.utils;


import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckUtils {

    /**
     * @param username 用户名
     * @param password 密码
     * @param iCheckResultListener 检查结果的监听
     */
    public static void checkPassword(String username,
                                     String password,
                                     ICheckResultListener iCheckResultListener) {
        if (isAnyBlank(username, password)) {
            iCheckResultListener.error("请输入账号或密码");
            return;
        }
        iCheckResultListener.success();
    }

    /**
     * @param css 字符串集
     * @return 传入的值是否全部为null
     */
    public static boolean isAnyBlank(final CharSequence... css){
        if (ArrayUtils.isEmpty(css)) {
            return true;
        }
        for (final CharSequence cs : css){
            if (StringUtils.isBlank(cs)) {
                return true;
            }
        }
        return false;
    }
    /**
     * 验证手机号
     * */
    public static boolean isMobileNO(String mobiles) {
        Pattern p = Pattern.compile("^((1[0-9][0-9]))\\d{8}$");
        Matcher m = p.matcher(mobiles);
        boolean matches = m.matches();
        return matches;
    }

    /**
     * 验证电话号码
     * */
    public static boolean isTelNO(String tel) {
        Pattern p = Pattern.compile("\\d{3}-\\d{8}|\\d{4}-\\d{7}");
        Matcher m = p.matcher(tel);
        boolean matches = m.matches();
        return matches;
    }

    /**
     * 验证密码
     * */
    public static boolean isPassword(String password) {
        Pattern p = Pattern.compile("\\w{6,16}");
        Matcher m = p.matcher(password);
        boolean matches = m.matches();
        return matches;
    }

    /**
     * 验证账号
     * */
    public static boolean isUsername(String username) {
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]{1,16}|\\w{2,16}");
        Matcher m = p.matcher(username);
        boolean matches = m.matches();
        return matches;
    }

    /**
     * 验证车牌号
     * */
    public static boolean isCarno(String carno) {
        Pattern p = Pattern.compile("^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$");
        Matcher m = p.matcher(carno);
        boolean matches = m.matches();
        return matches;
    }
    public interface ICheckResultListener {

        void success();

        void error(String errorMessage);
    }
}
